package com.app.micaihu.view.main.msgcenter.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.message.MsgCenter;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;

import java.util.List;

/**
 * Created by Guo on 2016/9/27.
 * 消息中心的适配器
 */
public class MsgCenterAdapter extends AppBaseAdapter<MsgCenter> {
    public MsgCenterAdapter(List<MsgCenter> list, Context context) {
        super(list, context);
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_msgcenter, null);

            viewHolder = new ViewHolder(convertView);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        MsgCenter msgCenter = list.get(position);

        // 只要有消息，就显示小红点，并且
        if (msgCenter != null) {
            LoadImageUtils.getInstance().loadCircleImage(viewHolder.civIcon, msgCenter.getIcon());
            viewHolder.tvName.setText(msgCenter.getName());
            if (TextUtils.equals(msgCenter.getNum(), "0") || TextUtils.isEmpty(msgCenter.getNum())) {
                viewHolder.tvNum.setVisibility(View.GONE);
//                viewHolder.tvPrompt.setVisibility(View.GONE);
            } else {
                viewHolder.tvNum.setVisibility(View.VISIBLE);
                viewHolder.tvNum.setBackgroundResource(R.drawable.detail_comment_count_bg);
                viewHolder.tvNum.setPadding(ViewSizeUtils.dp2px(context, 5.5f), ViewSizeUtils.dp2px(context, 0.7f), ViewSizeUtils.dp2px(context, 5.5f), ViewSizeUtils.dp2px(context, 0.7f));
                viewHolder.tvNum.setTextColor(context.getResources().getColor(R.color.common_font_color_6));
                viewHolder.tvNum.setText(msgCenter.getNum());

//                viewHolder.tvPrompt.setVisibility(View.VISIBLE);
//                viewHolder.tvPrompt.setText(msgCenter.getPrompt());
            }
            viewHolder.tvPrompt.setVisibility(View.VISIBLE);
            viewHolder.tvPrompt.setText(msgCenter.getPrompt());
        }


//        if(msgCenter != null){
//            LoadImageUtils.getInstance().loadCircleImage(viewHolder.civIcon,msgCenter.getIcon());
//            viewHolder.tvName.setText(msgCenter.getName());
//            if(TextUtils.equals(msgCenter.getNum(),"0") || TextUtils.isEmpty(msgCenter.getNum())){
//                viewHolder.tvNum.setVisibility(View.GONE);
//            }else{
//                viewHolder.tvNum.setVisibility(View.VISIBLE);
//                if(TextUtils.equals(msgCenter.getCate(),"1")){//只显示数字->当前逻辑是按照消息数大于1.
//                    viewHolder.tvNum.setBackgroundResource(R.drawable.detail_comment_count_bg);
//                    viewHolder.tvNum.setPadding(ViewSizeUtils.dp2px(context,5.5f),ViewSizeUtils.dp2px(context,0.7f),ViewSizeUtils.dp2px(context,5.5f),ViewSizeUtils.dp2px(context,0.7f));
//                    viewHolder.tvNum.setTextColor(context.getResources().getColor(R.color.common_white_color));
//                    viewHolder.tvNum.setText(msgCenter.getNum());
//                }else if(TextUtils.equals(msgCenter.getCate(),"2")){//拼接字符串->只有一条消息，显示xxx关注了你
//                    viewHolder.tvNum.setBackgroundResource(0);
//                    viewHolder.tvNum.setPadding(0,0,0,0);
//                    viewHolder.tvNum.setTextColor(context.getResources().getColor(R.color.user_tast_sign_promt));
//                    viewHolder.tvNum.setText(msgCenter.getNum()+msgCenter.getNotice());
//                }
//            }
//        }

        return convertView;
    }


    class ViewHolder {
        private CustomImageView civIcon;
        private TextView tvName;
        private TextView tvNum;
        private TextView tvPrompt;

        public ViewHolder(View convertView) {
            civIcon = (CustomImageView) convertView.findViewById(R.id.civ_icon);
            tvName = (TextView) convertView.findViewById(R.id.tv_name);
            tvNum = (TextView) convertView.findViewById(R.id.tv_num);
            tvPrompt = (TextView) convertView.findViewById(R.id.tv_prompt);
        }
    }
}




